

//
//  DictionaryViewController.swift
//  Swift 3.0 基础语法
//
//  Created by YYY on 2017/7/17.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import UIKit

class DictionaryViewController: CommonViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.green
        
        //字典的增删改
        demo2()
        // Do any additional setup after loading the view.
    }

    //字典的定义
    func demo0()
    {
        let dict = ["name" : 12,"age" : 1]
        print(dict)
        
        //数组字典
        let array = [
            ["name" : "def", "age" : 12],
            ["name" : "abc", "age" : 92]
        ]
        print(array)
    }
    
    //字典的增删改
    func demo1()
    {
        //不可变 let
        //可变 var
        var dict = ["key1" : "1", "key2" : "22"]
        //修改
        dict["key1"] = "100"
        //增加
        dict["key3"] = "300"
        //删除
        dict.removeValue(forKey: "key2")
        //hash 就是将字符串变成唯一的整数，便于查找，提高字典遍历速度
    }
    
    //字典的遍历
    func demo2()
    {
        let dict = ["name": "小敏","age": 20,"title": "BOSS"] as [String : Any]
        print(dict)
        
        //遍历
        for object in dict
        {
            print(object)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
